package com.cloud.workTest;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.read.listener.ReadListener;

import java.util.Map;

public class EasyExcelTest {

    public static void main(String[] args) {
        String filePath = "f://testExcel.xlsx";

        EasyExcel.read(filePath, new ReadListener() {
            @Override
            public boolean hasNext(AnalysisContext context) {
                Integer currentRow = context.readRowHolder().getRowIndex();
                System.out.println("current row is " + currentRow);
                if (currentRow < 1) {
                    return true;
                } else {
                    return false;
                }

            }

            @Override
            public void invokeHead(Map headMap, AnalysisContext context) {
                Integer size = headMap.size();
                for (int i = 0; i < size; ++i) {
                    ReadCellData<String> readCellData = (ReadCellData<String>) headMap.get(i);
                }
            }

            @Override
            public void invoke(Object o, AnalysisContext analysisContext) {
                Integer rows = analysisContext.readSheetHolder().getApproximateTotalRowNumber();
                System.out.println("excel 的行数是：" + rows);
            }

            @Override
            public void doAfterAllAnalysed(AnalysisContext analysisContext) {

            }
        }).sheet().doRead();

    }
}
